﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Interfaces;
using LinFu.IoC;
using CoreEx.Services;

namespace CoreEx.Database.Query
{
    public static class ExpressionExtensions
    {
        private static IServiceContainer _serviceContainer;

        static ExpressionExtensions()
        {
            _serviceContainer = ServiceLocator.Container;
        }

        public static IExpression WrapExpressionList(this IExpression[] expressions)
        {
            if (expressions == null || expressions.Length == 0)
                throw new ArgumentOutOfRangeException("expressions", "The expression list can not be null or empty");

            if (expressions.Length > 1)
                return _serviceContainer.GetService<IExpressionList>().AddRange(expressions);

            return expressions[0];
        }
    }
}
